<?php
require_once dirname(__FILE__) . '/libraries/ServiceBase.php';
/**
 * Help Service （彩虹帮助服务）
 */
class SDOServiceHelp extends ServiceBase
{
    // 正式环境开通彩虹版主服务
    const HELP_OP_URL = 'HELP_WSDL';
    // 测试环境开通彩虹帮助服务
    const PRE_HELP_OP_URL = 'PRE_HELP_WSDL';
    // 操作默认值
    const OPERATION_DEFAULT = 1;
    // 附加信息默认值
    const APPENDIX_DEFAULT = "";
    /**
     * 开通SDO彩虹帮助
     * 
     * @param string $message 错误信息
     * @param int $spId 公司ID
     * @param string $appId 产品ID
     * @param string $env 
     * @param int $operation 0 关闭，1开通
     * @return boolean 
     */
    public static function setOpenSysConfig (&$message, $spId, $appId, $env = 'pre', $operation=self::OPERATION_DEFAULT)
    {
        $op = 'SetOpenSysConfig';
        $wsdl = ($env === 'pre') ? sdk_fetch_config(SDK_ENV . self::PRE_HELP_OP_URL) : sdk_fetch_config(SDK_ENV . self::HELP_OP_URL);
        
        $params = array(
            'spId' => $spId , 
            'appId' => $appId , 
            'operation' => $operation , 
            'appendix' => self::APPENDIX_DEFAULT
        );
        $result = self::soapRequest($op, $params, $wsdl, array(), $message);
        // $message = count($result) === 2 ? $result : array(- 1 , '接口错误');
        if ($result===false) {
        	self::log("method: setOpenSysConfig\tparams: ".json_encode($params)."\tenv: {$env}\texception: ".$message, __CLASS__);
        	return false;
        }
        if ($result->SetOpenSysConfigResult == -9999) {
        	self::log("method: setOpenSysConfig\tparams: ".json_encode($params)."\tenv: {$env}\treturn: ".json_encode($result), __CLASS__);
        	return false;
        }
        self::log("method: setOpenSysConfig\tparams: ".json_encode($params)."\tenv: {$env}\treturn: ".json_encode($result), __CLASS__, true);
        return true;
    }
	/**
     * 自检函数
     */
    public static function selfTest() 
    {
    	$arr = array(
        	sdk_fetch_config(SDK_ENV . self::HELP_OP_URL),
        	sdk_fetch_config(SDK_ENV . self::PRE_HELP_OP_URL)
    	);
    	return self::curlTest($arr);
    }
} 
